/**
 * 
 */
package com.jubao.ejb.dao.interceptor;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

import org.apache.log4j.Logger;

/**
 * @author Conan
 *
 */
public class TracingInterceptor {
	Logger logger = Logger.getLogger(DefaultInterceptor.class.getName());
	
	@AroundInvoke
	   public Object log(InvocationContext ctx) throws Exception
	   {
		logger.info("*** TracingInterceptor intercepting " + ctx.getMethod().getName());
	      long start = System.currentTimeMillis();
	      try
	      {
	         return ctx.proceed();
	      }
	      catch(Exception e)
	      {
	         throw e;
	      }
	      finally
	      {
	         long time = System.currentTimeMillis() - start;
	         String method = ctx.getClass().getName() + "." + ctx.getMethod().getName() + "()";
	         logger.info("*** TracingInterceptor invocation of " + method + " took " + time + "ms");
	      }
	   }
}
